package com.nopay.cdxphone.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import androidx.annotation.NonNull;
import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.nopay.cdxphone.R;
import com.nopay.cdxphone.ui.adapter.CustomerAdapter;

/**
 * 联系客服
 */
public class DialogContactCustomer extends Dialog {

    private Activity mActivity;

    private static CustomerAdapter adapter;

    public DialogContactCustomer(@NonNull Activity context) {
        super(context, R.style.MyDialog);
        mActivity = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_contact_customer);
        setCanceledOnTouchOutside(true);

//        TextView tvTelNum = findViewById(R.id.tv_tel_num);
//        tvTelNum.setOnClickListener(v -> {
//            dismiss();
//
//            ClipboardUtils.copyText(tvTelNum.getText().toString());
//            ToastUtils.showShort("微信号已经粘贴到剪贴板里");
//            try {
//                Intent intent = new Intent(Intent.ACTION_MAIN);
//                ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
//                intent.addCategory(Intent.CATEGORY_LAUNCHER);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                intent.setComponent(cmp);
//                mActivity.startActivity(intent);
//            } catch (ActivityNotFoundException e) {
//                ToastUtils.showShort("检查到您手机没有安装微信，请安装后使用该功能");
//            }
//        });

        ListView lv_customer = findViewById(R.id.lv_customer);
        adapter = new CustomerAdapter(mActivity);
        lv_customer.setAdapter(adapter);
        lv_customer.setOnItemClickListener((parent, view, position, id) -> {
            dismiss();
            ClipboardUtils.copyText(adapter.getItem(position));
            ToastUtils.showShort("微信号已经粘贴到剪贴板里");
            try {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setComponent(cmp);
                mActivity.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                ToastUtils.showShort("检查到您手机没有安装微信，请安装后使用该功能");
            }
        });
    }

    public void show(String phoneNum) {
        super.show();
//        TextView tvTelNum = findViewById(R.id.tv_tel_num);
//        tvTelNum.setText(phoneNum);

        adapter.setDatas(phoneNum);
    }

}



